package com.automannn.springPractice.applicationContext.bean.create;

import com.automannn.springPractice.applicationContext.bean.factory.UserFactory;
import com.automannn.springPractice.applicationContext.bean.factory.impl.DefaultUserFactory;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Iterator;
import java.util.ServiceLoader;

public class SpecialBeanCreateBean {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:META-INF/special-bean-create-Application.xml");
        AutowireCapableBeanFactory beanFactory=context.getAutowireCapableBeanFactory();
        DefaultUserFactory bean = beanFactory.createBean(DefaultUserFactory.class);
        System.out.println(bean.getUser());
        demoLoader();
    }

    public static void demoLoader() {
        ServiceLoader<UserFactory> load = ServiceLoader.load(UserFactory.class, Thread.currentThread().getContextClassLoader());
        Iterator<UserFactory> iterator = load.iterator();
        while (iterator.hasNext()){
            UserFactory next = iterator.next();
            System.out.println(next.getUser());
        }
    }

}
